package com.eshop.we.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.eshop.we.exchange.dto.ExchangeDto;
import com.eshop.we.exchange.entity.Exchange;
import com.eshop.we.exchangedetail.entity.ExchangeDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 换书详情 Mapper 接口
 * </p>
 *
 * @author anonymity
 * @since 2018-07-06
 */
@Mapper
@Component
public interface ExchangeDetailMapper extends BaseMapper<ExchangeDetail> {

    @Update("update exchange_detail set is_del=1 where exchange_id=#{exchangeId} ")
    Integer updateDel(@Param("exchangeId") Integer exchangeId);

    @Select("select book_name from exchange_detail where exchange_id= #{exchangeId} ")
    List<String> selectListBook(@Param("exchangeId")Integer exchangeId);


    @Select( "select a.* ,u.real_name,u.mobile,s.name from ( select e.* ,b.book_name ,b.book_code ,b.press, b.author, b.category_title   from exchange e " +
            "left join exchange_detail d on e.id=d.exchange_id " +
            " left join book b on b.id=e.book_id   " +
            "where e.user_id !=#{userId} and d.book_name = #{book} and e.status =10 ) a " +
            "left join user u on a.user_id=u.id " +
            "left join school s on u.school_id=s.id" +
            "  order by  s.id=#{schoolId} ,a.ctime desc ")
    List<ExchangeDto> selectMathBook(@Param("userId")Integer userId,@Param("schoolId")Integer schoolId,@Param("book")String book);

    void batchInsert(Exchange exchange, List<String> details);
}
